###############################################
# === xenomorph_espionage_events.txt ===
###############################################
###############################################
# XENOMORPH ESPIONAGE EVENTS
# Pass 24: Stage completion events for the 6 Xenomorph operations.
###############################################

namespace = xenomorph_op

espionage_operation_event = {
	id = xenomorph_op.1
	title = xenomorph_op.1.name
	desc = xenomorph_op.1.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.1.a }
}

espionage_operation_event = {
	id = xenomorph_op.2
	title = xenomorph_op.2.name
	desc = xenomorph_op.2.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	immediate = {
		owner = { add_resource = { society_research = 200 } }
		from = { set_timed_country_flag = { flag = xeno_biological_survey_completed days = 10800 } }
	}

	option = { name = xenomorph_op.2.a }
}

espionage_operation_event = {
	id = xenomorph_op.10
	title = xenomorph_op.10.name
	desc = xenomorph_op.10.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.10.a }
}

espionage_operation_event = {
	id = xenomorph_op.11
	title = xenomorph_op.11.name
	desc = xenomorph_op.11.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.11.a }
}

espionage_operation_event = {
	id = xenomorph_op.12
	title = xenomorph_op.12.name
	desc = xenomorph_op.12.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	immediate = {
		from = { add_modifier = { modifier = xeno_country_infested days = 10800 } }
	}

	option = { name = xenomorph_op.12.a }
}

espionage_operation_event = {
	id = xenomorph_op.20
	title = xenomorph_op.20.name
	desc = xenomorph_op.20.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.20.a }
}

espionage_operation_event = {
	id = xenomorph_op.21
	title = xenomorph_op.21.name
	desc = xenomorph_op.21.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.21.a }
}

espionage_operation_event = {
	id = xenomorph_op.22
	title = xenomorph_op.22.name
	desc = xenomorph_op.22.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.22.a }
}

espionage_operation_event = {
	id = xenomorph_op.23
	title = xenomorph_op.23.name
	desc = xenomorph_op.23.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	immediate = {
		from = { add_modifier = { modifier = xeno_country_compromised_lineage days = 3650 } }
	}

	option = { name = xenomorph_op.23.a }
}

espionage_operation_event = {
	id = xenomorph_op.30
	title = xenomorph_op.30.name
	desc = xenomorph_op.30.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.30.a }
}

espionage_operation_event = {
	id = xenomorph_op.31
	title = xenomorph_op.31.name
	desc = xenomorph_op.31.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.31.a }
}

espionage_operation_event = {
	id = xenomorph_op.32
	title = xenomorph_op.32.name
	desc = xenomorph_op.32.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.32.a }
}

espionage_operation_event = {
	id = xenomorph_op.33
	title = xenomorph_op.33.name
	desc = xenomorph_op.33.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.33.a }
}

espionage_operation_event = {
	id = xenomorph_op.34
	title = xenomorph_op.34.name
	desc = xenomorph_op.34.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	immediate = {
		from = { add_modifier = { modifier = xeno_country_leadership_compromised days = 7200 } }
	}

	option = { name = xenomorph_op.34.a }
}

espionage_operation_event = {
	id = xenomorph_op.40
	title = xenomorph_op.40.name
	desc = xenomorph_op.40.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.40.a }
}

espionage_operation_event = {
	id = xenomorph_op.41
	title = xenomorph_op.41.name
	desc = xenomorph_op.41.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.41.a }
}

espionage_operation_event = {
	id = xenomorph_op.42
	title = xenomorph_op.42.name
	desc = xenomorph_op.42.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.42.a }
}

espionage_operation_event = {
	id = xenomorph_op.43
	title = xenomorph_op.43.name
	desc = xenomorph_op.43.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.43.a }
}

espionage_operation_event = {
	id = xenomorph_op.44
	title = xenomorph_op.44.name
	desc = xenomorph_op.44.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	immediate = {
		from = { add_modifier = { modifier = xeno_country_brood_uprising days = 1825 } }
	}

	option = { name = xenomorph_op.44.a }
}

espionage_operation_event = {
	id = xenomorph_op.50
	title = xenomorph_op.50.name
	desc = xenomorph_op.50.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.50.a }
}

espionage_operation_event = {
	id = xenomorph_op.51
	title = xenomorph_op.51.name
	desc = xenomorph_op.51.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.51.a }
}

espionage_operation_event = {
	id = xenomorph_op.52
	title = xenomorph_op.52.name
	desc = xenomorph_op.52.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.52.a }
}

espionage_operation_event = {
	id = xenomorph_op.53
	title = xenomorph_op.53.name
	desc = xenomorph_op.53.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.53.a }
}

espionage_operation_event = {
	id = xenomorph_op.54
	title = xenomorph_op.54.name
	desc = xenomorph_op.54.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.54.a }
}

espionage_operation_event = {
	id = xenomorph_op.55
	title = xenomorph_op.55.name
	desc = xenomorph_op.55.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	option = { name = xenomorph_op.55.a }
}

espionage_operation_event = {
	id = xenomorph_op.56
	title = xenomorph_op.56.name
	desc = xenomorph_op.56.desc
	picture = GFX_evt_alien_artifacts
	is_triggered_only = yes

	immediate = {
		from = { add_modifier = { modifier = xeno_country_planetary_consumption days = 3650 } }
	}

	option = { name = xenomorph_op.56.a }
}

###############################################
# === xenomorph_lustful_void_compat_events.txt ===
###############################################
###############################################
# Xenomorph + Lustful Void Compatibility Events
#
# External-mod compatibility events for Lustful Void civic/trait logic.
###############################################

# Xenomorph + Lustful Void Compatibility Events
# Place in: events/xenomorph_lustful_void_compat_events.txt

namespace = xeno_lv_compat

# Run this from yearly_country_pulse/on_yearly_pulse.
# It handles the dynamic slave/no-slave and opposite-sex captive bonuses.
espionage_operation_event = {
	id = xeno_lv_compat.10
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			owner = { has_valid_civic = civic_xenomorph_matriarchs_hunger }
			owner = { has_valid_civic = civic_xenomorph_patriarchs_dominion }
		}
	}

	immediate = {
		# Matriarchal Hunger: penalty if no slaves.
		if = {
			limit = {
				owner = { has_valid_civic = civic_xenomorph_matriarchs_hunger }
				NOT = { xeno_has_any_slave_pop = yes }
			}
			add_modifier = { modifier = xeno_matriarchal_hunger_no_slaves_penalty days = 370 }
		}
		else_if = {
			limit = { has_modifier = xeno_matriarchal_hunger_no_slaves_penalty }
			remove_modifier = xeno_matriarchal_hunger_no_slaves_penalty
		}

		# Patriarchal Dominion: penalty if no slaves.
		if = {
			limit = {
				owner = { has_valid_civic = civic_xenomorph_patriarchs_dominion }
				NOT = { xeno_has_any_slave_pop = yes }
			}
			add_modifier = { modifier = xeno_patriarchal_dominion_no_slaves_penalty days = 370 }
		}
		else_if = {
			limit = { has_modifier = xeno_patriarchal_dominion_no_slaves_penalty }
			remove_modifier = xeno_patriarchal_dominion_no_slaves_penalty
		}

		# Matriarchal Hunger: +25% pop growth if any enslaved all-male species exists.
		if = {
			limit = {
				owner = { has_valid_civic = civic_xenomorph_matriarchs_hunger }
				xeno_has_enslaved_all_male_species = yes
			}
			add_modifier = { modifier = xeno_matriarchal_hunger_all_male_slave_bonus days = 370 }
		}
		else_if = {
			limit = { has_modifier = xeno_matriarchal_hunger_all_male_slave_bonus }
			remove_modifier = xeno_matriarchal_hunger_all_male_slave_bonus
		}

		# Patriarchal Dominion: +25% pop growth if any enslaved all-female species exists.
		if = {
			limit = {
				owner = { has_valid_civic = civic_xenomorph_patriarchs_dominion }
				xeno_has_enslaved_all_female_species = yes
			}
			add_modifier = { modifier = xeno_patriarchal_dominion_all_female_slave_bonus days = 370 }
		}
		else_if = {
			limit = { has_modifier = xeno_patriarchal_dominion_all_female_slave_bonus }
			remove_modifier = xeno_patriarchal_dominion_all_female_slave_bonus
		}
	}
}

# Optional startup cleanup: makes the main Xenomorph species match the civic sex trait.
# This intentionally targets Xenomorph species only, not enslaved host species.
espionage_operation_event = {
	id = xeno_lv_compat.20
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		OR = {
			owner = { has_valid_civic = civic_xenomorph_matriarchs_hunger }
			owner = { has_valid_civic = civic_xenomorph_patriarchs_dominion }
		}
	}

	immediate = {
		if = {
			limit = { has_valid_civic = civic_xenomorph_matriarchs_hunger }
			every_owned_species = {
				limit = { has_trait = trait_xenomorph }
				remove_trait = trait_lv_all_male
				add_trait = trait_lv_all_female
			}
		}
		if = {
			limit = { has_valid_civic = civic_xenomorph_patriarchs_dominion }
			every_owned_species = {
				limit = { has_trait = trait_xenomorph }
				remove_trait = trait_lv_all_female
				add_trait = trait_lv_all_male
			}
		}
	}
}


# Brood Queen Hive LV synergy.
# When LV is loaded AND a planet has Brood Queen Hive, apply the LV bonus modifier.
# Fires from on_yearly_pulse_country.
espionage_operation_event = {
	id = xeno_lv_compat.30
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		has_global_flag = lustful_void_mod_loaded
		any_owned_planet = {
			has_building = building_xenomorph_brood_queen_hive
		}
	}

	immediate = {
		every_owned_planet = {
			if = {
				limit = {
					has_building = building_xenomorph_brood_queen_hive
					NOT = { has_modifier = xenomorph_brood_queen_hive_lv_bonus }
				}
				add_modifier = { modifier = xenomorph_brood_queen_hive_lv_bonus days = -1 }
			}
			if = {
				limit = {
					NOT = { has_building = building_xenomorph_brood_queen_hive }
					has_modifier = xenomorph_brood_queen_hive_lv_bonus
				}
				remove_modifier = xenomorph_brood_queen_hive_lv_bonus
			}
		}
	}
}


# Detect Lustful Void at game start by checking for known LV civics.
# Sets has_global_flag = lustful_void_mod_loaded for downstream events.
espionage_operation_event = {
	id = xeno_lv_compat.1
	hide_window = yes
	is_triggered_only = yes

	immediate = {
		if = {
			limit = {
				NOT = { has_global_flag = lustful_void_mod_loaded }
				OR = {
					has_civic = civic_lv_divine_coupling
					has_civic = civic_lv_sex_crazed_breeders
					has_civic = civic_lv_milk_ranchers
					has_civic = civic_lv_sex_slaves
					has_civic = civic_lv_pleasure_suits
					has_civic = civic_lv_sexculture
					has_civic = civic_lv_franchised_prostitution
					has_civic = civic_lv_sex_contractors
					has_civic = civic_lv_machine_nurture_protocols
					has_civic = civic_lv_gestalt_pod_bondage
				}
			}
			set_global_flag = lustful_void_mod_loaded
		}
	}
}


# ===== 3_61 D3: raid_pop stage events =====
espionage_operation_event = {
	id = xenomorph_op.60
	title = xenomorph_op.60.name
	desc = xenomorph_op.60.desc
	picture = GFX_evt_spymaster
	is_triggered_only = yes
	immediate = { }
	option = { name = xenomorph_op.60.a }
}

espionage_operation_event = {
	id = xenomorph_op.61
	title = xenomorph_op.61.name
	desc = xenomorph_op.61.desc
	picture = GFX_evt_spymaster
	is_triggered_only = yes
	immediate = {
		hidden_effect = {
			random_list = {
				55 = {
					# success — chances from dead record (0.55)
					save_event_target_as = xeno_raid_attacker
					target = {
						save_event_target_as = xeno_raid_defender
						random_owned_planet = {
							limit = {
								is_colony = yes
								any_owned_pop_group = { is_xenomorph = no }
							}
							save_event_target_as = xeno_raid_planet
						}
						owner = { add_resource = { unity = -150 } }
					}
					xeno_kidnap_saved_planet_pops = yes
					espionage_operation_event = { id = xeno_pic_events.26 }
				}
				25 = {
					# partial — undetected, reduced reward
					owner = { add_resource = { food = 200 unity = 50 } }
				}
				20 = {
					# critical failure — detected (0.20)
					owner = { add_resource = { influence = -50 } }
					target = {
						add_opinion_modifier = {
							who = root
							modifier = opinion_xenomorph_raid_detected
						}
					}
				}
			}
		}
	}
	option = { name = xenomorph_op.61.a }
}

# ===== 3_61 D3: hive_cell stage events =====
espionage_operation_event = {
	id = xenomorph_op.70
	title = xenomorph_op.70.name
	desc = xenomorph_op.70.desc
	picture = GFX_evt_spymaster
	is_triggered_only = yes
	immediate = { }
	option = { name = xenomorph_op.70.a }
}

espionage_operation_event = {
	id = xenomorph_op.71
	title = xenomorph_op.71.name
	desc = xenomorph_op.71.desc
	picture = GFX_evt_spymaster
	is_triggered_only = yes
	immediate = {
		hidden_effect = {
			random_list = {
				45 = {
					# success (0.45)
					espionage_operation_event = { id = xeno_pic_events.23 }
					target = {
						random_owned_planet = {
							limit = { is_colony = yes }
							add_modifier = { modifier = xenomorph_post_battle_shock days = 360 }
						}
					}
				}
				25 = {
					owner = { add_resource = { influence = -25 } }
				}
				30 = {
					# critical failure — detected (0.30)
					owner = { add_resource = { influence = -75 } }
				}
			}
		}
	}
	option = { name = xenomorph_op.71.a }
}
